/** @namespace app.model.PlatformTag */
module.exports = app => {
  const {INTEGER, STRING} = app.Sequelize;
  const PlatformTag = app.model.define('platform_tag', {
    id: {type: INTEGER, autoIncrement: true, primaryKey: true},
    name: {type: STRING, allowNull: false},
    key: {type: STRING, allowNull: false},
    url: {type: STRING, allowNull: false},
  }, {
    updatedAt: false,
    tableName: 'spider_platform_tag',
  });

  PlatformTag.associate = () => {
    app.model.PlatformTag.belongsTo(app.model.PlatformType,
        {foreignKey: 'platform_type_id'});

    app.model.PlatformTag.belongsTo(app.model.Platform);
    app.model.PlatformTag.belongsTo(app.model.Type);

    app.model.PlatformTag.belongsTo(app.model.PlatformType,
        {foreignKey: 'platform_type_id'});

    app.model.PlatformType.hasMany(app.model.PlatformTag,
        {foreignKey: 'platform_type_id'});
  };

  return PlatformTag;
};